package com.wwg.threads.binghe.concurrent.executor.callable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TaskA implements Runnable {

    private static final Logger LOGGER = LoggerFactory.getLogger(TaskA.class);

    private Callable callable;

    private int errorFlag;

    public Callable getCallable() {
        return callable;
    }

    public void setCallable(Callable callable) {
        this.callable = callable;
    }

    public TaskA(Callable callable, int errorFlag) {
        this.callable = callable;
        this.errorFlag = errorFlag;
    }

    @Override
    public void run() {
        TaskResult<ResultParams> objectTaskResult = new TaskResult<>();
        try {
            LOGGER.info("任务执行开始》》》");

            int x = 100 / errorFlag;

            LOGGER.info("任务执行结束《《《");
            LOGGER.info("封装回调");
            objectTaskResult.setSuccess(true);
            objectTaskResult.setErrorMessage("no error find");
            objectTaskResult.setResult(new ResultParams("拿到", "100万"));
        } catch (Exception e) {
            objectTaskResult.setSuccess(false);
            objectTaskResult.setErrorMessage("error occur:" + e.getMessage());
            objectTaskResult.setResult(new ResultParams("亏了", "5块钱"));
        } finally {

            callable.call(objectTaskResult);
        }

    }
}
